package com.example.seven.mynews.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;

import com.example.seven.mynews.R;
import com.example.seven.mynews.adapter.ViewPagerAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by seven on 16-6-28.
 */
public class GuideActivity extends AppCompatActivity {
    private ViewPager viewPager;
    private List<View> views;

    private ImageView[] imageViews;
    private int[] dots;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_guide);
        initDots();
        initView();


    }
    private void initView(){
        viewPager = (ViewPager)findViewById(R.id.viewPage);
        views = new ArrayList<>();
        View v1 = getLayoutInflater().inflate(R.layout.layout_1,null);//填充布局
        View v2 = getLayoutInflater().inflate(R.layout.layout_2,null);//填充布局
        View v3 = getLayoutInflater().inflate(R.layout.layout_3,null);//填充布局

        views.add(v1);
        views.add(v2);
        views.add(v3);

        viewPager.setAdapter(new ViewPagerAdapter(views));

        viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                //选中当前页
                for (int i = 0; i < imageViews.length; i++) {
                    if (i == position) {
                        //讲选中的效果图标替换
                        imageViews[i].setImageResource(R.drawable.login_point_selected);
                    } else {
                        imageViews[i].setImageResource(R.drawable.login_point);
                    }
                }
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });

    }

    private void initDots(){
        dots = new int[]{R.id.icon_1,R.id.icon_2,R.id.icon_3};
        imageViews = new ImageView[dots.length];
        for (int i = 0;i<dots.length;i++){
            imageViews[i] = (ImageView) findViewById(dots[i]);
        }
    }

    public void enterHome(View view){
        Intent aIntent = new Intent(GuideActivity.this,MainActivity.class);
        startActivity(aIntent);
        finish();
    }

}
